import brandsApi from '../../api/brands.api';

const state={
  data:[],
  brandGoods: []
};

const getters={
  brands: (state: any) => {
    return state.data;
  },

  brandGoods: (state: any) => {
    return state.brandGoods;
  }
};

const actions={
  async getBrands({commit}:any,params: any={}){
    const data=await brandsApi.getBrands(params);
    commit('setData', data);
  },

  async getBrandGoods({commit}:any,id: string){
    const params={
      join:"goods",
      filter:`id||$eq||${id}`
    };
    const data=await brandsApi.getBrands(params);
    commit('setBrandGoods', data);
  }
};

const mutations={
  setData(state: any, data: any){
    state.data = data;
  },

  setBrandGoods(state: any, data: any){
    state.brandGoods=data;
  }
};

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}